package com.azxc.rapid.plus.system.controller;

import com.azxc.rapid.core.boot.ctrl.RapidController;
import com.azxc.rapid.core.mp.support.Condition;
import com.azxc.rapid.core.tenant.annotation.NonDS;
import com.azxc.rapid.core.tool.api.R;
import com.azxc.rapid.plus.system.service.IDictBizPlusService;
import com.azxc.rapid.system.entity.DictBiz;
import com.azxc.rapid.system.vo.DictBizVO;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 控制器
 */
@NonDS
@RestController
@AllArgsConstructor
@RequestMapping("/systemPlus/dictBizPlus")
@Api(value = "业务字典", tags = "业务字典")
public class DictBizPlusController extends RapidController {

	private final IDictBizPlusService dictService;


	/**
	 * 根据字典code获取子列表
	 *
	 * @param code
	 * @return
	 */
	@GetMapping("/child-listByCode")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "列表", notes = "传入dict")
	public R<List<DictBizVO>> childListByCode(@ApiIgnore @RequestParam String code) {
		DictBiz dictBiz = new DictBiz();
		dictBiz.setCode(code);
		dictBiz.setDictKey("-1");
		DictBiz data = dictService.getOne(Condition.getQueryWrapper(dictBiz));
		List<DictBizVO> dictBizVOS = new ArrayList<>();
		if (data != null) {
			Long parentId = data.getId();
			Map<String, Object> dict = new HashMap<>();
			dict.put("code", code);
			dict.put("parentId", parentId);
			dictBizVOS = dictService.childList(dict, parentId);
		}
		return R.data(dictBizVOS);
	}

}
